<?php

/**
 * Controller_teaching
 * 奖励，惩罚设置
 */

class Controller_award extends MyApp {


    /** 首页 **/
    public function actionIndex()
    {

    }
	/** ------------------------------- 学生奖励、惩罚----------------------------------------- **/	
	/** 学生惩罚奖励-项目行为列表 **/
    public function actionStudentSetList ()
    {  
		// 跳转1=奖励，2=惩罚
		$award_type   			= $this->get->award_type;
		$where = "";
		
		if(!empty($award_type)){
			$where .= " AND award_type = '{$award_type}' ";			
		}
		// 惩罚，奖励名称
		$award_tname= $this->award_type[$award_type];
		
    	// 分页     
        YOU::loadLib('page', "", '0');
        $tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_award` WHERE is_show='1' {$where}");
		
        $count = $tmp['count'];
        $page_total = ceil($count/PAGE_LIMIT);
        // 当前页                  
        $p = intval($_GET['p']);
        if ($p == 0){
            $p  = 1;
        }
        if ($p > 1){	
            $start = PAGE_LIMIT * ($p-1);
        }else{
            $start = 0;
        }
		
        $award_lists = $this->db->fetchAll("SELECT * FROM `tbl_award` WHERE is_show='1' {$where} ORDER BY award_id DESC LIMIT {$start}, ".PAGE_LIMIT."");		

        $page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
        $page->next_page   = '下一页>';
        $page->pre_page    = '<上一页';
        $page->style_path  = "static/page_style";
       
	    $this->tpl->assign("page", $page->show(4, "yahoo"));
		$this->tpl->assign("award_lists", $award_lists);
		$this->tpl->assign("award_type", $award_type);
		$this->tpl->assign("award_tname", $award_tname);

        $this->tpl->display('award/student.set.list.tpl.php');
    }
	/** 学生奖励、惩罚-项目行为修改 **/
    public function actionStudentSetUpdate()
    {   
		
        $award_type   		= $this->get->award_type;
		$award_id   		= $this->get->award_id;	
		// 奖励
		$award_data = $this->db->fetchRow("SELECT * FROM `tbl_award` WHERE award_type= {$award_type} AND is_show = 1 AND award_id={$award_id}");
		// 惩罚，奖励名称
		$award_tname= $this->award_type[$award_type];

	    if (empty($award_data)){
            Helper_Client::alert("信息不存在");
        }
	
        if ($_POST){ 

			$award_title   			= $this->post->award_title;
			$award_credit   		= $this->post->award_credit;			

            // 写入数据库
            $info = array(
				    	
			"award_title"  			=> $award_title,
			"award_credit"       	=> $award_credit,
			"status"                => 1,
			"create_time"           => date("Y-m-d H:i:s"),
			"update_time"           => "0000-00-00 00:00:00",  

			 );

          $this->db->do_update("tbl_award", $info, "award_id='{$award_id}'");

          // 跳转
          Helper_Client::location("修改成功", "index.php?a=award.studentsetlist&award_type={$award_type}");

         }

            $this->tpl->assign("award_data", $award_data);
			$this->tpl->assign("award_tname", $award_tname);
	        $this->tpl->display("award/student.set.update.tpl.php");
    } 
	/** 学生奖励---项目添加 **/
    public function actionAwardStudentAdd()
    {        
		$award_type   		= $this->get->award_type;
        if ($_POST){ 

			$award_title   			= $this->post->award_title;
			$award_credit   		= $this->post->award_credit;

			if (empty($award_title)){
            Helper_Client::alert("奖励行为不能为空");
			}
			if (empty($award_credit)){
            Helper_Client::alert("增加学分不能为空");
			}
		
			// 奖励写入数据库
			$info = array( 
				
			"award_title"  			=> $award_title,
			"award_credit"       	=> $award_credit,
			// 1 =奖励
			"award_type"       		=> 1,
			// 1 = 学生奖励、惩罚设定 
			"is_show"       		=> 1,
			"status"                => 1,
			"create_time"           => date("Y-m-d H:i:s"),
			"update_time"           => "0000-00-00 00:00:00",  
			 );
     		 $this->db->do_insert("tbl_award", $info);
          
          Helper_Client::location("添加成功", "index.php?a=award.studentsetlist&award_type=1");

         }
          
         $this->tpl->display("award/student.award.add.tpl.php");
    }
	/** 学生惩罚---项目添加 **/
    public function actionPunishStudentAdd()
    {        
		$award_type   		= $this->get->award_type;
        if ($_POST){ 

            $award_title_mistake    = $this->post->award_title_mistake;
            $award_credit_mistake   = $this->post->award_credit_mistake;

			if (empty($award_title_mistake)){
            Helper_Client::alert("惩罚行为不能为空");
			}
			if (empty($award_credit_mistake)){
            Helper_Client::alert("扣除学分不能为空");
			}

			// 惩罚写入数据库
			$info = array( 
				
			"award_title"  			=> $award_title_mistake,
			"award_credit"       	=> $award_credit_mistake,
			// 2 =惩罚
			"award_type"       		=> 2,
			// 1 = 学生奖励、惩罚设定 
			"is_show"       		=> 1,
			"status"                => 1,
			"create_time"           => date("Y-m-d H:i:s"),
			"update_time"           => "0000-00-00 00:00:00",  
			 );
     		$this->db->do_insert("tbl_award", $info);

          Helper_Client::location("添加成功", "index.php?a=award.studentsetlist&award_type=2");

         }
          
         $this->tpl->display("award/student.punish.add.tpl.php");
    }
	/** 学生奖励-惩罚-项目-删除 **/
	public function actionStudentSetDel ()
	{
		$award_id 	= (int)$this->get->award_id;
		$award_type = (int)$this->get->award_type;
		$this->db->query("DELETE  FROM `tbl_award` WHERE award_id='{$award_id}'");
		Helper_Client::location("删除成功", "index.php?a=award.studentsetlist&award_type={$award_type}");
	}
/** ------------------------------- 学生奖励、惩罚列表----------------------------------------- **/	
	/** 学生惩罚奖励 行为列表 **/
    public function actionAwardStudentList ()
    {  
    	 // 分页     
        YOU::loadLib('page', "", '0');
        $tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_award_stu`");
        $count = $tmp['count'];
        $page_total = ceil($count/PAGE_LIMIT);
        // 当前页                  
        $p = intval($_GET['p']);
        if ($p == 0){
            $p  = 1;
        }
        if ($p > 1){	
            $start = PAGE_LIMIT * ($p-1);
        }else{
            $start = 0;
        }
		
        $stu_lists = $this->db->fetchAll("SELECT * FROM `tbl_award_stu` ORDER BY stu_id DESC LIMIT {$start}, ".PAGE_LIMIT."");
		
		foreach($stu_lists as $key=>$value){
			// 学生
			$student_data = $this->db->fetchRow("SELECT * FROM `tbl_student` WHERE student_id={$value['student_id']}");
		
			$stu_lists[$key]['student_name'] = $student_data['student_name'];
			$stu_lists[$key]['student_no'] = $student_data['student_no'];
			
			// 奖惩、名称
			$award_data = $this->db->fetchRow("SELECT * FROM `tbl_award` WHERE award_id={$value['award_id']}");
			$stu_lists[$key]['award_title'] = $award_data['award_title'];
			$stu_lists[$key]['award_credit'] = $award_data['award_credit'];
			// 奖励、惩罚
			$stu_lists[$key]['award_type'] = $this->award_type[$award_data['award_type']];
		
		}		

        $page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
        $page->next_page   = '下一页>';
        $page->pre_page    = '<上一页';
        $page->style_path  = "static/page_style";
       
	    $this->tpl->assign("page", $page->show(4, "yahoo"));
		$this->tpl->assign("stu_lists", $stu_lists);
        $this->tpl->display('award/student.list.tpl.php');
    }
	

	/** 学生奖励添加 **/
    public function actionStudentAwardNewAdd()
    {	
		// 奖励
		$award_lists = $this->db->fetchAll("SELECT * FROM `tbl_award` WHERE award_type= 1 AND is_show = 1");

        if ($_POST){ 

            $student_no				= $this->post->student_no;
            $student_name			= $this->post->student_name;
			$award_id   			= $this->post->award_id;
			// 学生
			$student_data = $this->db->fetchRow("SELECT `student_id` FROM `tbl_student` WHERE student_no= '{$student_no}' AND student_name='{$student_name}'");

			if (empty($student_data)){
            Helper_Client::alert("学生不存在");
			}

			// 奖励内容
			$award_data = $this->db->fetchRow("SELECT * FROM `tbl_award` WHERE award_id= '{$award_id}'");
				// 奖励写入数据库
				$info = array( 
				
				"student_id"  			=> $student_data['student_id'],
				"award_id"  			=> $award_data['award_id'],
				"status"                => 1,
				"create_time"           => date("Y-m-d H:i:s"),
				"update_time"           => "0000-00-00 00:00:00",  

				 );
		
			  $this->db->do_insert("tbl_award_stu", $info);
			  
			  Helper_Client::location("添加成功", "index.php?a=award.awardstudentlist");
			}			
                     
         $this->tpl->assign("award_lists", $award_lists); 
         $this->tpl->display("award/student.awardadd.tpl.php");
    }
	/** 学生惩罚添加 **/
    public function actionStudentPunishmentNewAdd()
    {	
		// 惩罚
		$award_lists = $this->db->fetchAll("SELECT * FROM `tbl_award` WHERE award_type= 2 AND is_show = 1");

        if ($_POST){ 

            $student_no				= $this->post->student_no;
            $student_name			= $this->post->student_name;
			$award_id   			= $this->post->award_id;
			// 学生
			$student_data = $this->db->fetchRow("SELECT `student_id` FROM `tbl_student` WHERE student_no= '{$student_no}' AND student_name='{$student_name}'");

			if (empty($student_data)){
            Helper_Client::alert("学生不存在");
			}

			// 惩罚内容
			$award_data = $this->db->fetchRow("SELECT * FROM `tbl_award` WHERE award_id= '{$award_id}'");
				// 惩罚写入数据库
				$info = array( 
				
				"student_id"  			=> $student_data['student_id'],
				"award_id"  			=> $award_data['award_id'],
				"status"                => 1,
				"create_time"           => date("Y-m-d H:i:s"),
				"update_time"           => "0000-00-00 00:00:00",  

				 );
			
			  $this->db->do_insert("tbl_award_stu", $info);
			  
			  Helper_Client::location("添加成功", "index.php?a=award.awardstudentlist");
			}			
                     
         $this->tpl->assign("award_lists", $award_lists); 
         $this->tpl->display("award/student.punishmentdadd.tpl.php");
    }
	/** 学生奖励、惩罚修改 **/
    public function actionStudentUpdate()
    {   

        $stu_id	   = (int)$this->get->stu_id;
		
		// 行为
        $stu_data  = $this->db->fetchRow("SELECT * FROM `tbl_award_stu` WHERE `stu_id`='{$stu_id}'");
		// 自己的奖励\奖励的内容 1=学生
		$award_data = $this->db->fetchRow("SELECT * FROM `tbl_award` WHERE award_id= '{$stu_data['award_id']}'");
		// 惩罚或奖励的全部行为
        $award_lists  = $this->db->fetchAll("SELECT * FROM `tbl_award` WHERE `award_type`={$award_data['award_type']}  AND is_show = 1");
		// 学生
		$student_data = $this->db->fetchRow("SELECT `student_name`,`student_no` FROM `tbl_student` WHERE student_id= '{$stu_data['student_id']}'");
	
	    if (empty($stu_data)){
            Helper_Client::alert("信息不存在");
        }

        if ($_POST){ 

			$award_id   			= $this->post->award_id;  					

            // 写入数据库
            $info = array(
				    	
			"award_id"       		=> $award_id,
			"status"                => 1,
			"create_time"           => date("Y-m-d H:i:s"),
			"update_time"           => "0000-00-00 00:00:00",  

			 );

          $this->db->do_update("tbl_award_stu", $info, "stu_id='{$stu_id}'");

          // 跳转
          Helper_Client::location("修改成功", "index.php?a=award.awardstudentlist");

         }

            $this->tpl->assign("award_lists", $award_lists);
			$this->tpl->assign("student_data", $student_data);
	        $this->tpl->display("award/student.update.tpl.php");
    } 
	/** 学生奖励、惩罚删除 **/
    public function actionStudentDel()
    {
        $stu_id = $this->get->stu_id;   
        $this->db->query("DELETE  FROM tbl_award_stu WHERE stu_id='{$stu_id}'");
         // 跳转
        Helper_Client::location("删除成功", "index.php?a=award.awardstudentlist");
    }
	// 学生行为列表查询
	 public function actionStudentInquireList ()
    {	
		// 查询条件
		$award_type   = $this->get->award_type;
		$student_name = $this->get->student_name;
		$from         = $this->get->from;
		$to           = $this->get->to;

		$where = " ";
		
		if(!empty($award_type)){
			$where .= " AND b.award_type = '{$award_type}' ";
			$this->tpl->assign("award_type", $award_type);
			
		}

		if(!empty($student_name)){
			// 取得学生名称
			$where .= " AND a.student_id IN ( SELECT `student_id` FROM `tbl_student` WHERE student_name LIKE '%{$student_name}%' ) ";
			$this->tpl->assign("student_name", $student_name);

		}

		if(!empty($from)){
			$where .= " AND a.create_time >= '{$from}' ";
			$this->tpl->assign("from", $from);
		}

		if(!empty($to)){
			$where .= " AND a.create_time <= '{$to}+1' ";
			$this->tpl->assign("to", $to);
		}
    	 // 分页     
        YOU::loadLib('page', "", '0');
        $tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_award_stu` AS a,`tbl_award` AS b WHERE a.award_id=b.award_id {$where} ");
        $count = $tmp['count'];
        $page_total = ceil($count/PAGE_LIMIT);
        // 当前页                  
        $p = intval($_GET['p']);
        if ($p == 0){
            $p  = 1;
        }
        if ($p > 1){	
            $start = PAGE_LIMIT * ($p-1);
        }else{
            $start = 0;
        }
		
        $stu_lists = $this->db->fetchAll("SELECT b.*,a.* FROM `tbl_award_stu` AS a ,`tbl_award` AS b WHERE a.award_id=b.award_id {$where} ORDER BY stu_id DESC LIMIT {$start}, ".PAGE_LIMIT."");
		
		foreach($stu_lists as $key=>$value){

			// 学生
			$student_data = $this->db->fetchRow("SELECT * FROM `tbl_student` WHERE student_id={$value['student_id']}");
		
			$stu_lists[$key]['student_name'] = $student_data['student_name'];
			$stu_lists[$key]['student_no']	 = $student_data['student_no'];
			
			// 奖励、惩罚
			$stu_lists[$key]['award_type']	 = $this->award_type[$value['award_type']];
			// 时间转换
			$stu_lists[$key]['create_time']  = date("Y-m-d", strtotime($value['create_time']));
		
		}		
		
        $page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
        $page->next_page   = '下一页>';
        $page->pre_page    = '<上一页';
        $page->style_path  = "static/page_style";
       
	    $this->tpl->assign("page", $page->show(4, "yahoo"));
		$this->tpl->assign("stu_lists", $stu_lists);
        $this->tpl->display('award/student.inquire.tpl.php');
    }
	/** ------------------------------- 班级奖励、惩罚添加------------------------------------ **/	
	/** 班级惩罚奖励-项目行为列表 **/
    public function actionClassSetList ()
    {  
		// 跳转1=奖励，2=惩罚
		$award_type   			= $this->get->award_type;
		$where = "";
		
		if(!empty($award_type)){
			$where .= " AND award_type = '{$award_type}' ";			
		}
		// 惩罚，奖励名称
		$award_tname= $this->award_type[$award_type];
		
    	// 分页     
        YOU::loadLib('page', "", '0');
        $tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_award` WHERE is_show='2' {$where}");
		
        $count = $tmp['count'];
        $page_total = ceil($count/PAGE_LIMIT);
        // 当前页                  
        $p = intval($_GET['p']);
        if ($p == 0){
            $p  = 1;
        }
        if ($p > 1){	
            $start = PAGE_LIMIT * ($p-1);
        }else{
            $start = 0;
        }
		
        $award_lists = $this->db->fetchAll("SELECT * FROM `tbl_award` WHERE is_show='2' {$where} ORDER BY award_id DESC LIMIT {$start}, ".PAGE_LIMIT."");		

        $page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
        $page->next_page   = '下一页>';
        $page->pre_page    = '<上一页';
        $page->style_path  = "static/page_style";
       
	    $this->tpl->assign("page", $page->show(4, "yahoo"));
		$this->tpl->assign("award_lists", $award_lists);
		$this->tpl->assign("award_type", $award_type);
		$this->tpl->assign("award_tname", $award_tname);

        $this->tpl->display('award/class.set.list.tpl.php');
    }
	/** 班级奖励项目添加 **/
    public function actionAwardClassAdd()
    {        
		
        if ($_POST){ 

			$award_title   			= $this->post->award_title;
			$award_credit   		= $this->post->award_credit;

			// 书写内容不能为空
			if (empty($award_title)){
            Helper_Client::alert("请填写奖励名称");
			}
			if (empty($award_credit)){
            Helper_Client::alert("请填写奖励分数");
			}

			// 奖励写入数据库	
			$info = array( 
					
				"award_title"  			=> $award_title,
				"award_credit"       	=> $award_credit,
				// 2 =奖励
				"award_type"       		=> 1,
				// 2= 班级惩罚、奖励设定
				"is_show"       		=> 2,
				"status"                => 1,
				"create_time"           => date("Y-m-d H:i:s"),
				"update_time"           => "0000-00-00 00:00:00",  

			 );


			  $this->db->do_insert("tbl_award", $info);		
            
          Helper_Client::location("添加成功", "index.php?a=award.classsetlist&award_type=1");

         }
          
         $this->tpl->display("award/class.award.add.tpl.php");
    }
	/** 班级惩罚项目添加 **/
	public function actionPunishClassAdd()
    {        
		
        if ($_POST){ 

            $award_title    	= $this->post->award_title;
            $award_credit   	= $this->post->award_credit;

			// 书写内容不能为空
			if (empty($award_title)){
            Helper_Client::alert("请填写惩罚名称");
			}
			if (empty($award_credit)){
            Helper_Client::alert("请填写惩罚分数");
			}

			// 惩罚写入数据库
			$info = array( 
					
			"award_title"  			=> $award_title,
			"award_credit"   		=> $award_credit,
			// 2 =惩罚
			"award_type"       		=> 2,
			// 2= 班级惩罚、奖励设定
			"is_show"       		=> 2,
			"status"                => 1,
			"create_time"           => date("Y-m-d H:i:s"),
			"update_time"           => "0000-00-00 00:00:00",  

			 );
		    $this->db->do_insert("tbl_award", $info);
            
          Helper_Client::location("添加成功", "index.php?a=award.classsetlist&award_type=2");

         }
          
         $this->tpl->display("award/class.punish.add.tpl.php");
    }
    /** 班级奖励、惩罚-项目行为修改 **/
    public function actionClassSetUpdate()
    {   
		
        $award_title    	= $this->post->award_title;
        $award_type   		= $this->get->award_type;
		$award_id   		= $this->get->award_id;	
		// 奖励
		$award_data = $this->db->fetchRow("SELECT * FROM `tbl_award` WHERE award_type= {$award_type} AND is_show = 2 AND award_id={$award_id}");
		// 惩罚，奖励名称
		$award_tname= $this->award_type[$award_type];

	    if (empty($award_data)){
            Helper_Client::alert("信息不存在");
        }

        if ($_POST){ 

			$award_credit   			= $this->post->award_credit;  					

            // 写入数据库
            $info = array(
			"award_title"  			=> $award_title,
			"award_credit"          => $award_credit,	
			"update_time"           => date("Y-m-d H:i:s"),
			 );

          $this->db->do_update("tbl_award", $info, "award_id ='{$award_id }'");

          // 跳转
          Helper_Client::location("修改成功", "index.php?a=award.classsetlist&award_type={$award_type}	");

         }

            $this->tpl->assign("award_data", $award_data);
			$this->tpl->assign("award_tname", $award_tname);
	        $this->tpl->display("award/class.set.update.tpl.php");
    }
    /** 班级奖励-惩罚-项目-删除 **/
	public function actionClassSetDel ()
	{
		$award_id 	= (int)$this->get->award_id;
		$award_type = (int)$this->get->award_type;
		$this->db->query("DELETE  FROM `tbl_award` WHERE award_id='{$award_id}'");
		Helper_Client::location("删除成功", "index.php?a=award.classsetlist&award_type={$award_type}");
	}
	/** ------------------------------- 班级奖励、惩罚列表------------------------------------- **/
	/** 班级惩罚奖励 行为列表 **/
    public function actionAwardClassList ()
    {  
    	 // 分页     
        YOU::loadLib('page', "", '0');
        $tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_award_clas`");
        $count = $tmp['count'];
        $page_total = ceil($count/PAGE_LIMIT);
        // 当前页                  
        $p = intval($_GET['p']);
        if ($p == 0){
            $p  = 1;
        }
        if ($p > 1){	
            $start = PAGE_LIMIT * ($p-1);
        }else{
            $start = 0;
        }
		
        $clas_lists = $this->db->fetchAll("SELECT * FROM `tbl_award_clas` ORDER BY clas_id DESC LIMIT {$start}, ".PAGE_LIMIT."");
		
		foreach($clas_lists as $key=>$value){
			// 班级
			$class_data = $this->db->fetchRow("SELECT * FROM `tbl_class` WHERE class_id={$value['class_id']}");		
			$clas_lists[$key]['class_name'] = $class_data['class_name'];
			
			// 奖惩、名称
			$award_data = $this->db->fetchRow("SELECT * FROM `tbl_award` WHERE award_id={$value['award_id']}");
			$clas_lists[$key]['award_title'] = $award_data['award_title'];
			$clas_lists[$key]['award_credit'] = $award_data['award_credit'];
			
			// 奖励、惩罚
			$clas_lists[$key]['award_type'] = $this->award_type[$award_data['award_type']];
		
		}		

        $page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
        $page->next_page   = '下一页>';
        $page->pre_page    = '<上一页';
        $page->style_path  = "static/page_style";
       
	    $this->tpl->assign("page", $page->show(4, "yahoo"));
		$this->tpl->assign("clas_lists", $clas_lists);
        $this->tpl->display('award/class.list.tpl.php');
    }
	/** 班级奖励添加 **/
    public function actionClassAwardNewAdd()
    {	
		// 奖励is_show =2 班级 award_type=1 奖励
		$award_lists = $this->db->fetchAll("SELECT * FROM `tbl_award` WHERE award_type= 1 AND is_show = 2");

        if ($_POST){ 

            $class_name				= $this->post->class_name;
			$award_id   			= $this->post->award_id;
			// 查看班级是否存在
			$class_data = $this->db->fetchRow("SELECT * FROM `tbl_class` WHERE class_name='{$class_name}'");

			if(empty($class_data)){

				Helper_Client::alert("班级不存在");
			}
		
			// 奖励写入数据库
			$info = array( 
				
			"class_id"  			=> $class_data['class_id'],
			"award_id"  			=> $award_id,
			"status"                => 1,
			"create_time"           => date("Y-m-d H:i:s"),
			"update_time"           => "0000-00-00 00:00:00",  

			);
		
			  $this->db->do_insert("tbl_award_clas", $info);
			  
			  Helper_Client::location("添加成功", "index.php?a=award.awardclasslist");
			}			
                     
         $this->tpl->assign("award_lists", $award_lists); 
         $this->tpl->display("award/class.awardadd.tpl.php");
    }
	/** 班级惩罚添加 **/
    public function actionClassPunishmentNewAdd()
    {	
		// 奖励is_show =2 班级 award_type=2 惩罚
		$award_lists = $this->db->fetchAll("SELECT * FROM `tbl_award` WHERE award_type= 2 AND is_show = 2");

        if ($_POST){ 

            $class_name				= $this->post->class_name;
			$award_id   			= $this->post->award_id;
			// 查看班级是否存在
			$class_data = $this->db->fetchRow("SELECT * FROM `tbl_class` WHERE class_name='{$class_name}'");

			if(empty($class_data)){

				Helper_Client::alert("班级不存在");
			}
		
			// 奖励写入数据库
			$info = array( 
				
			"class_id"  			=> $class_data['class_id'],
			"award_id"  			=> $award_id,
			"status"                => 1,
			"create_time"           => date("Y-m-d H:i:s"),
			"update_time"           => "0000-00-00 00:00:00",  

			);
		
			  $this->db->do_insert("tbl_award_clas", $info);
			  
			  Helper_Client::location("添加成功", "index.php?a=award.awardclasslist");
			}			
                     
         $this->tpl->assign("award_lists", $award_lists); 
         $this->tpl->display("award/class.punishmentdadd.tpl.php");
    }
	/** 班级奖励、惩罚修改 **/
    public function actionClassUpdate()
    {   

        $clas_id	   = (int)$this->get->clas_id;
		
		// 行为
        $clas_data  = $this->db->fetchRow("SELECT * FROM `tbl_award_clas` WHERE `clas_id`='{$clas_id}'");
		// 自己的奖励\奖励的内容 
		$award_data = $this->db->fetchRow("SELECT * FROM `tbl_award` WHERE award_id= '{$clas_data['award_id']}'");
		// 惩罚或奖励的全部行为 is_show=2 班级
        $award_lists  = $this->db->fetchAll("SELECT * FROM `tbl_award` WHERE `award_type`={$award_data['award_type']}  AND is_show = 2");
		// 班级
		$class_data = $this->db->fetchRow("SELECT `class_id`,`class_name` FROM `tbl_class` WHERE class_id= '{$clas_data['class_id']}'");
		
	    if (empty($class_data)){
            Helper_Client::alert("信息不存在");
        }

        if ($_POST){ 

			$award_id   			= $this->post->award_id;  					

            // 写入数据库
            $info = array(
				    	
			"award_id"       		=> $award_id,
			"status"                => 1,
			"create_time"           => date("Y-m-d H:i:s"),
			"update_time"           => "0000-00-00 00:00:00",  

			 );

          $this->db->do_update("tbl_award_clas", $info, "clas_id='{$clas_id}'");

          // 跳转
          Helper_Client::location("修改成功", "index.php?a=award.awardclasslist");

         }

            $this->tpl->assign("award_lists", $award_lists);
			$this->tpl->assign("class_data", $class_data);
	        $this->tpl->display("award/class.update.tpl.php");
    } 
	/** 班级奖励、惩罚删除 **/
    public function actionClassDel()
    {
        $clas_id = $this->get->clas_id;   
        $this->db->query("DELETE  FROM `tbl_award_clas` WHERE clas_id='{$clas_id}'");
         // 跳转
        Helper_Client::location("删除成功", "index.php?a=award.awardclasslist");
    }

	/** 班级行为列表查询 **/
	public function actionClassInquireList()
	{
		// 查询条件
		$award_type = $this->get->award_type;
		$class_name = $this->get->class_name;
		$from       = $this->get->from;
		$to         = $this->get->to;


		$where = " ";
		
		if(!empty($award_type)){
			$where .= " AND b.award_type = '{$award_type}' ";
			$this->tpl->assign("award_type", $award_type);
		}

		if(!empty($class_name)){
			// 取得班级名称
			$where .= " AND a.class_id IN ( SELECT class_id FROM `tbl_class` WHERE class_name LIKE '%{$class_name}%' ) ";
			$this->tpl->assign("class_name", $class_name);
		}

		if(!empty($from)){
			$where .= " AND a.create_time >= '{$from} 00:00:00' ";
			$this->tpl->assign("from", $from);
		}

		if(!empty($to)){
			$where .= " AND a.create_time <= '{$to} 23:59:59'";
			$this->tpl->assign("to", $to);
		}
		
   		// 分页     
        YOU::loadLib('page', "", '0');
        $tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_award_clas` AS a,`tbl_award` AS b WHERE a.award_id=b.award_id {$where} ");
        $count = $tmp['count'];
        $page_total = ceil($count/PAGE_LIMIT);
        // 当前页                  
        $p = intval($_GET['p']);
        if ($p == 0){
            $p  = 1;
        }
        if ($p > 1){	
            $start = PAGE_LIMIT * ($p-1);
        }else{
            $start = 0;
        }
		
        $clas_lists = $this->db->fetchAll("SELECT b.*,a.* FROM `tbl_award_clas` AS a,`tbl_award` AS b WHERE a.award_id=b.award_id {$where} ORDER BY clas_id DESC LIMIT {$start}, ".PAGE_LIMIT."");
//var_dump($clas_lists);
        //echo ("SELECT a.*,b.* FROM `tbl_award_clas` AS a,`tbl_award` AS b WHERE a.award_id=b.award_id {$where} ORDER BY clas_id DESC LIMIT {$start}, ".PAGE_LIMIT."");

        foreach($clas_lists as $key=>$value){
			// 班级
			$class_data = $this->db->fetchRow("SELECT * FROM `tbl_class` WHERE class_id={$value['class_id']}");		
			$clas_lists[$key]['class_name']		= $class_data['class_name'];						
			// 奖励、惩罚
			$clas_lists[$key]['award_type']		= $this->award_type[$value['award_type']];
			// 时间转换
			//$clas_lists[$key]['create_time']	= date("Y-m-d", strtotime($value['create_time']));
		
		}		

        $page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
        $page->next_page   = '下一页>';
        $page->pre_page    = '<上一页';
        $page->style_path  = "static/page_style";
       
	    $this->tpl->assign("page", $page->show(4, "yahoo"));
		$this->tpl->assign("clas_lists", $clas_lists);
        $this->tpl->display('award/class.inquire.tpl.php');
    }	
	
}

?>